<?php
class Task extends AppModel {
	var $name = 'Task';
	
	var $belongsTo = array(
		/*'CreatedUser' => array(
			'className' => 'User',
			'foreignKey' => 'created_users_id'
		),*/
		'ResUser' => array (
			'className' => 'User',
			'foreignKey' => 'working_users_id'
		)
	);
	
	var $hasMany = array (
		'TaskItem' => array (
			'className' => 'TaskItem',
			'foreignKey' => 'tasks_id'
		)
	);
	
	function getTasksBySprintAndStatus($sprintId = null, $statusId = null) {
		$sql = "SELECT * FROM tasks as Task 
				LEFT JOIN users as ResUser on Task.working_users_id = ResUser.id
				WHERE Task.sprints_id=$sprintId and Task.status_id = $statusId";
		
		return $this->query($sql);
	}
}
?>